package com.maezia.tdr.common;

import com.maezia.tdr.common.enums.StatusCodeEnum;
import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {
    private int code;
    private String msg;
    private T data;

    public Result() {
    }

    private Result(int code, String message) {
        this.code = code;
        this.msg = message;
    }

    private Result(T data, int code, String message) {
        this.code = code;
        this.msg = message;
        this.data = data;
    }

    public static <T> Result<T> success() {
        return new Result<T>(StatusCodeEnum.SUCCESS.getCode(), StatusCodeEnum.SUCCESS.getMessage());
    }

    public static <T> Result<T> success(T data) {
        return new Result<T>(data, StatusCodeEnum.SUCCESS.getCode(), StatusCodeEnum.SUCCESS.getMessage());
    }

    public static <T> Result<T> error() {
        return new Result<T>(StatusCodeEnum.SYSTEM_ERROR.getCode(), StatusCodeEnum.SYSTEM_ERROR.getMessage());
    }

    public static <T> Result<T> error(String msg) {
        return new Result<T>(StatusCodeEnum.SYSTEM_ERROR.getCode(), msg);
    }

    public static <T> Result<T> error(Integer code, String msg) {
        return new Result<T>(code, msg);
    }
}
